package core {
	/**
	 * ...
	 * @author Zszen John
	 */
	public class TimeFormat {
		public static function formatTime(time:String, format:String='y-m-d H:M:S'):Date {
			//2010-11-19 20:30:00
			var poolSplit:Array = []
			var poolKeyword:Array = ['y', 'm', 'd', 'H', 'M', 'S'];
			//var poolKeywordHas:Array =[false,false,false,false,false,false]
			for (var i:int = 0; i < poolKeyword.length; i++) {
				var keyword:String = poolKeyword[i];
				var keyword_indexStart:int = format.indexOf(keyword)
				var keyword_splitSimbol:String
				if (keyword_indexStart != -1) {
					keyword_splitSimbol = format.substr(keyword_indexStart+1, 1)
					poolSplit.push(keyword_splitSimbol)
				}else {
					poolSplit.push(null)
				}
			}
			var splitIndex:int = 0
			var splitOldIndex:int = 0
			var numStr:String
			var poolNum:Array=[]
			for (var j:int = 0; j < poolSplit.length; j++) {
				var item:String = poolSplit[j];
				if (item != null) {
					if (item != "") {
						splitIndex = time.indexOf(item, splitOldIndex)
						numStr = time.substring(splitOldIndex, splitIndex)
						splitOldIndex = splitIndex + item.length
					}else {
						numStr = time.substring(splitOldIndex)
					}
				}else {
					numStr=null
				}
				poolNum.push(parseInt(numStr))
			}
			var date:Date = new Date(poolNum[0], poolNum[1] - 1, poolNum[2], poolNum[3], poolNum[4], poolNum[5])
			return date
		}
	}

}